﻿
@model IEnumerable<Person>

@{
    IEnumerable<Person> persons = new[] {
        new Person{FirstName ="Martin", LastName="Strimpfl"},
        new Person{FirstName = "Jakub", LastName="Strimpfl"},
        new Person{FirstName = "Jan", LastName = "Strimpfl"}
    };
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    <div>
        @using (Html.BeginForm())
        {
            foreach (var person in persons)
            {
                var index = Guid.NewGuid().ToString();

                <input type="checkbox" value="@index" name="persons.index" @Checked(person) />@person.FirstName@: @person.LastName<br />

                <input type="hidden" value="@person.FirstName" name="persons[@index].FirstName" />
                <input type="hidden" value="@person.LastName" name="persons[@index].LastName" />
            }
            <input type="submit" />
        }
    </div>
</body>
</html>

@helper Checked(Person person)
{
    if (this.Model.Any(m => m.FirstName.Equals(person.FirstName) && m.LastName.Equals(person.LastName)))
    {
        @:checked="checked"
    }
}